package JUnit;

import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import protocol.Headers;
import Servlets.WhatsAppConstatnts;

public class send extends mainTest {
	@Before
	public void setUp() throws Exception {
		_url = "send";
	}

	@Test
	public void test405() {
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"GET /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		assertTrue(response1.contains("HTTP/1.1 " + Headers.STATUS_405));
	}

	@Test
	public void test403() {
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		assertTrue(response1.contains(Headers.STATUS_403));
	}

	@Test
	public void testERROR_711() {
		String response1 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		String cookie = this.getCookie(response1);
		String response2 = this.runtest(new RunnableClient("localhost", 9969,
				"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie
						+ "\n\nUserName=yochailehman2&Phone=0546861622\n$"));

		assertTrue(response2.contains(WhatsAppConstatnts.ERROR_711));
	}

	@Test
	public void testERROR_836() {
		String response1 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		String cookie = this.getCookie(response1);
		String response2 = this.runtest(new RunnableClient("localhost", 9969,
				"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie
						+ "\n\nType=yochailehman2&Target=0546861622\n$"));

		assertTrue(response2.contains(WhatsAppConstatnts.ERROR_711));
	}

	@Test
	public void testERROR_771() {
		String response1 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		String cookie = this.getCookie(response1);
		String response2 = this.runtest(new RunnableClient("localhost", 9969,
				"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie
						+ "\n\nType=Direct&Target=4440546861622\n$"));

		assertTrue(response2.contains(WhatsAppConstatnts.ERROR_711));

		String response3 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\nCookie: "
								+ cookie
								+ "\n\nType=Group&Target=4440546861622&Content=gggggggggg\n$"));

		assertTrue(response3.contains(WhatsAppConstatnts.ERROR_771));
	}

	@Test
	public void testSendDirect() {
		String response5 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
		String cookie2 = this.getCookie(response5);
		String response1 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		String cookie = this.getCookie(response1);
		String response3 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\nCookie: "
								+ cookie2
								+ "\n\nType=Direct&Target=0546861622&Content=gggggggggg\n$"));
		assertTrue(response3.contains("Message Sent!"));
	}

	@Test
	public void testSendGroup() {
		String response5 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
		String cookie2 = this.getCookie(response5);

		String response6 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd2&Phone=1234562\n$"));
		String cookie3 = this.getCookie(response6);

		this.runtest(new RunnableClient("localhost", 9969,
				"POST /create_group.jsp HTTP/1.1\nCookie: " + cookie2 + "\n\n"
						+ WhatsAppConstatnts.GROUP_NAME
						+ "=TestGroup1&Users=userToAdd,userToAdd2\n$"));

		String response1 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		String cookie = this.getCookie(response1);
		String response3 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\nCookie: "
								+ cookie2
								+ "\n\nType=Group&Target=TestGroup1&Content=gggggggggg\n$"));
		assertTrue(response3.contains("Message Sent!"));
	}
}
